<template>
  <PageContainer>
    <Header :title="title" />
    <view class="hb-p-4">
      <PersonalAuth
        v-if="authType === AuthTypeEnum.PERSONAL"
        :personalRealNameAuth="personalRealNameAuth!"
      />
      <EnterpriseAuth
        v-if="authType === AuthTypeEnum.ENTERPRISE"
        :enterpriseRealNameAuth="enterpriseRealNameAuth!"
      />
      <OrganizationAuth
        v-if="authType === AuthTypeEnum.ORGANIZATION"
        :organizationRealNameAuth="organizationRealNameAuth!"
      />
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* realNameAuth 实名认证 */
  import { AuthTypeEnum, authTypeText } from '@/enums/LoginEnum';

  import {
    EnterpriseRealNameAuth,
    OrganizationRealNameAuth,
    PersonalRealNameAuth,
  } from '@/api/realNameAuth/type';
  import PersonalAuth from './components/PersonalAuth.vue';
  import EnterpriseAuth from './components/EnterpriseAuth.vue';
  import OrganizationAuth from './components/OrganizationAuth.vue';
  import { botCertificationDetail } from '@/api/realNameAuth';
  const authType = ref<AuthTypeEnum>(AuthTypeEnum.PERSONAL);

  const personalRealNameAuth = ref<PersonalRealNameAuth>();
  const enterpriseRealNameAuth = ref<EnterpriseRealNameAuth>();
  const organizationRealNameAuth = ref<OrganizationRealNameAuth>();
  const title = computed(() => {
    return authType.value === AuthTypeEnum.PERSONAL
      ? '身份信息'
      : authType.value === AuthTypeEnum.ENTERPRISE
      ? '企业主体信息'
      : '主体信息';
  });
  customOnload<'RealNameAuth'>((options) => {
    authType.value = options.authType;
    queryAuthDetail();
  });

  const queryAuthDetail = async () => {
    const res = await botCertificationDetail();
    if (authType.value === AuthTypeEnum.PERSONAL) {
      personalRealNameAuth.value = res as PersonalRealNameAuth;
    } else if (authType.value === AuthTypeEnum.ENTERPRISE) {
      enterpriseRealNameAuth.value = res as EnterpriseRealNameAuth;
    } else if (authType.value === AuthTypeEnum.ORGANIZATION) {
      organizationRealNameAuth.value = res as OrganizationRealNameAuth;
    }
  };
</script>

<style lang="scss" scoped></style>
